package org.ytor.core.scheduler;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.ytor.common.scheduler.support.timewheel.ITimeWheelScheduler;

/**
 * created by yangtong on 2025/5/21 21:27:54
 * <br />
 * 时间轮配置
 */
@Configuration
public class TimeWheelConfig {

//    private final List<Task> allTask = new ArrayList<>();
//
//    @Autowired
//    public void init(ApplicationContext applicationContext) {
//        String[] names = applicationContext.getBeanNamesForType(Task.class);
//        for (String name : names) {
//            allTask.add(applicationContext.getBean(name, Task.class));
//        }
//    }

    @Bean
    public ITimeWheelScheduler timeWheelScheduler() {
        //List<TimeWheelTask> list = allTask.stream().map(i -> new TimeWheelTask("0/3 * * * * ?", i)).toList();

        ITimeWheelScheduler instance = ITimeWheelScheduler.instance();
        //list.forEach(instance::addTask);
        instance.start();
        return instance;
    }
}
